package day05;

import javafx.util.Pair;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

public class CounterWordsWithMap {
    public static void main(String[] args) {
       Map<String,Integer> map=new TreeMap<>();
       String [] words="   To know everything is to know   nothing   ".trim().toLowerCase().split("\\s+");
        System.err.println(Arrays.asList(words));
        for(String word:words){
            if(!map.containsKey(word)){
                map.put(word,1);//int->Integer boxing
            }else{
                int old=map.get(word);
                map.put(word,old+1);
            }
        }
        //System.out.println(map);//debug
        System.out.println(map.keySet());//Keyset
        System.out.println(map.values());
        //map遍历的方式
        for(String key:map.keySet()){
            System.out.println(key+":"+map.get(key));
        }

        for(Map.Entry<String,Integer> pair:map.entrySet()){
            System.out.println(pair.getKey()+":"+pair.getValue());
        }


    }
}
